using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace DocumentManagement
{
  /// <summary>
  /// Tfiles Data Object Class
  /// </summary>
  public partial class DOTfiles
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Tfiles FILENO
		/// </summary>
		public const string RowFILENO = "FILENO";

		/// <summary>
		/// The Table Column for the Tfiles ILPNO
		/// </summary>
		public const string RowILPNO = "ILPNO";

		/// <summary>
		/// The Table Column for the Tfiles NBSNO
		/// </summary>
		public const string RowNBSNO = "NBSNO";

		/// <summary>
		/// The Table Column for the Tfiles FTYPE
		/// </summary>
		public const string RowFTYPE = "FTYPE";

		/// <summary>
		/// The Table Column for the Tfiles LOCNO
		/// </summary>
		public const string RowLOCNO = "LOCNO";

		/// <summary>
		/// The Table Column for the Tfiles FSTATUS
		/// </summary>
		public const string RowFSTATUS = "FSTATUS";

		/// <summary>
		/// The Table Column for the Tfiles FUSER
		/// </summary>
		public const string RowFUSER = "FUSER";

		/// <summary>
		/// The Table Column for the Tfiles FEMPNO
		/// </summary>
		public const string RowFEMPNO = "FEMPNO";

		/// <summary>
		/// The Table Column for the Tfiles FDATETIME
		/// </summary>
		public const string RowFDATETIME = "FDATETIME";

		/// <summary>
		/// The Table Column for the Tfiles FTRANDTL
		/// </summary>
		public const string RowFTRANDTL = "FTRANDTL";

		/// <summary>
		/// The Table Column for the Tfiles FCREATED
		/// </summary>
		public const string RowFCREATED = "FCREATED";

		/// <summary>
		/// The Table Column for the Tfiles FCREATEDBY
		/// </summary>
		public const string RowFCREATEDBY = "FCREATEDBY";

		/// <summary>
		/// The Table Column for the Tfiles FNOTES
		/// </summary>
		public const string RowFNOTES = "FNOTES";

		/// <summary>
		/// The Table Column for the Tfiles FHOLD56
		/// </summary>
		public const string RowFHOLD56 = "FHOLD56";

		/// <summary>
		/// The Table Column for the Tfiles FNOBD
		/// </summary>
		public const string RowFNOBD = "FNOBD";

		/// <summary>
		/// The Table Column for the Tfiles FNOTD
		/// </summary>
		public const string RowFNOTD = "FNOTD";

		/// <summary>
		/// The Table Column for the Tfiles FLBLPRT
		/// </summary>
		public const string RowFLBLPRT = "FLBLPRT";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTfiles_Create";
private const string m_StoredProcedureConstDelete = "spTfiles_Delete";
private const string m_StoredProcedureConstRetrieve = "spTfiles_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTfiles_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTfiles_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_FILENO;
		private string m_ILPNO;
		private string m_NBSNO;
		private string m_FTYPE;
		private string m_LOCNO;
		private string m_FSTATUS;
		private string m_FUSER;
		private string m_FEMPNO;
		private DateTime m_FDATETIME;
		private string m_FTRANDTL;
		private DateTime m_FCREATED;
		private string m_FCREATEDBY;
		private string m_FNOTES;
		private bool m_FHOLD56;
		private bool m_FNOBD;
		private bool m_FNOTD;
		private bool m_FLBLPRT;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTfiles> m_Tfiless = new List<DOTfiles>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTfiles() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// FILENO
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FILENO
		/// </remarks>
		public string FILENO
		{
			get { return (this.m_FILENO); }
			set { this.m_FILENO = value; }
		}

		/// <summary>
		/// ILPNO
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles ILPNO
		/// </remarks>
		public string ILPNO
		{
			get { return (this.m_ILPNO); }
			set { this.m_ILPNO = value; }
		}

		/// <summary>
		/// NBSNO
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles NBSNO
		/// </remarks>
		public string NBSNO
		{
			get { return (this.m_NBSNO); }
			set { this.m_NBSNO = value; }
		}

		/// <summary>
		/// FTYPE
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FTYPE
		/// </remarks>
		public string FTYPE
		{
			get { return (this.m_FTYPE); }
			set { this.m_FTYPE = value; }
		}

		/// <summary>
		/// LOCNO
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles LOCNO
		/// </remarks>
		public string LOCNO
		{
			get { return (this.m_LOCNO); }
			set { this.m_LOCNO = value; }
		}

		/// <summary>
		/// FSTATUS
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FSTATUS
		/// </remarks>
		public string FSTATUS
		{
			get { return (this.m_FSTATUS); }
			set { this.m_FSTATUS = value; }
		}

		/// <summary>
		/// FUSER
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FUSER
		/// </remarks>
		public string FUSER
		{
			get { return (this.m_FUSER); }
			set { this.m_FUSER = value; }
		}

		/// <summary>
		/// FEMPNO
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FEMPNO
		/// </remarks>
		public string FEMPNO
		{
			get { return (this.m_FEMPNO); }
			set { this.m_FEMPNO = value; }
		}

		/// <summary>
		/// FDATETIME
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FDATETIME
		/// </remarks>
		public DateTime FDATETIME
		{
			get { return (this.m_FDATETIME); }
			set { this.m_FDATETIME = value; }
		}

		/// <summary>
		/// FTRANDTL
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FTRANDTL
		/// </remarks>
		public string FTRANDTL
		{
			get { return (this.m_FTRANDTL); }
			set { this.m_FTRANDTL = value; }
		}

		/// <summary>
		/// FCREATED
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FCREATED
		/// </remarks>
		public DateTime FCREATED
		{
			get { return (this.m_FCREATED); }
			set { this.m_FCREATED = value; }
		}

		/// <summary>
		/// FCREATEDBY
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FCREATEDBY
		/// </remarks>
		public string FCREATEDBY
		{
			get { return (this.m_FCREATEDBY); }
			set { this.m_FCREATEDBY = value; }
		}

		/// <summary>
		/// FNOTES
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FNOTES
		/// </remarks>
		public string FNOTES
		{
			get { return (this.m_FNOTES); }
			set { this.m_FNOTES = value; }
		}

		/// <summary>
		/// FHOLD56
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FHOLD56
		/// </remarks>
		public bool FHOLD56
		{
			get { return (this.m_FHOLD56); }
			set { this.m_FHOLD56 = value; }
		}

		/// <summary>
		/// FNOBD
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FNOBD
		/// </remarks>
		public bool FNOBD
		{
			get { return (this.m_FNOBD); }
			set { this.m_FNOBD = value; }
		}

		/// <summary>
		/// FNOTD
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FNOTD
		/// </remarks>
		public bool FNOTD
		{
			get { return (this.m_FNOTD); }
			set { this.m_FNOTD = value; }
		}

		/// <summary>
		/// FLBLPRT
		/// </summary>
		/// <remarks>
		/// This property contains the Tfiles FLBLPRT
		/// </remarks>
		public bool FLBLPRT
		{
			get { return (this.m_FLBLPRT); }
			set { this.m_FLBLPRT = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTfiles> Tfiless
	{
	  get { return m_Tfiless; }
	  set { m_Tfiless = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowFILENO + "=" + this.FILENO);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowFILENO].ToString() != "")
			this.FILENO = dr[RowFILENO].ToString();

		if (dr[RowILPNO].ToString() != "")
			this.ILPNO = dr[RowILPNO].ToString();

		if (dr[RowNBSNO].ToString() != "")
			this.NBSNO = dr[RowNBSNO].ToString();

		if (dr[RowFTYPE].ToString() != "")
			this.FTYPE = dr[RowFTYPE].ToString();

		if (dr[RowLOCNO].ToString() != "")
			this.LOCNO = dr[RowLOCNO].ToString();

		if (dr[RowFSTATUS].ToString() != "")
			this.FSTATUS = dr[RowFSTATUS].ToString();

		if (dr[RowFUSER].ToString() != "")
			this.FUSER = dr[RowFUSER].ToString();

		if (dr[RowFEMPNO].ToString() != "")
			this.FEMPNO = dr[RowFEMPNO].ToString();

		if (dr[RowFDATETIME].ToString() != "")
			this.FDATETIME = DateTime.Parse(dr[RowFDATETIME].ToString());

		if (dr[RowFTRANDTL].ToString() != "")
			this.FTRANDTL = dr[RowFTRANDTL].ToString();

		if (dr[RowFCREATED].ToString() != "")
			this.FCREATED = DateTime.Parse(dr[RowFCREATED].ToString());

		if (dr[RowFCREATEDBY].ToString() != "")
			this.FCREATEDBY = dr[RowFCREATEDBY].ToString();

		if (dr[RowFNOTES].ToString() != "")
			this.FNOTES = dr[RowFNOTES].ToString();

		if (dr[RowFHOLD56].ToString() != "")
			this.FHOLD56 = bool.Parse(dr[RowFHOLD56].ToString());

		if (dr[RowFNOBD].ToString() != "")
			this.FNOBD = bool.Parse(dr[RowFNOBD].ToString());

		if (dr[RowFNOTD].ToString() != "")
			this.FNOTD = bool.Parse(dr[RowFNOTD].ToString());

		if (dr[RowFLBLPRT].ToString() != "")
			this.FLBLPRT = bool.Parse(dr[RowFLBLPRT].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTfiles Tfiles = new DOTfiles();
			
					if (dr[RowFILENO].ToString() != "")
			Tfiles.FILENO = dr[RowFILENO].ToString();

		if (dr[RowILPNO].ToString() != "")
			Tfiles.ILPNO = dr[RowILPNO].ToString();

		if (dr[RowNBSNO].ToString() != "")
			Tfiles.NBSNO = dr[RowNBSNO].ToString();

		if (dr[RowFTYPE].ToString() != "")
			Tfiles.FTYPE = dr[RowFTYPE].ToString();

		if (dr[RowLOCNO].ToString() != "")
			Tfiles.LOCNO = dr[RowLOCNO].ToString();

		if (dr[RowFSTATUS].ToString() != "")
			Tfiles.FSTATUS = dr[RowFSTATUS].ToString();

		if (dr[RowFUSER].ToString() != "")
			Tfiles.FUSER = dr[RowFUSER].ToString();

		if (dr[RowFEMPNO].ToString() != "")
			Tfiles.FEMPNO = dr[RowFEMPNO].ToString();

		if (dr[RowFDATETIME].ToString() != "")
			Tfiles.FDATETIME = DateTime.Parse(dr[RowFDATETIME].ToString());

		if (dr[RowFTRANDTL].ToString() != "")
			Tfiles.FTRANDTL = dr[RowFTRANDTL].ToString();

		if (dr[RowFCREATED].ToString() != "")
			Tfiles.FCREATED = DateTime.Parse(dr[RowFCREATED].ToString());

		if (dr[RowFCREATEDBY].ToString() != "")
			Tfiles.FCREATEDBY = dr[RowFCREATEDBY].ToString();

		if (dr[RowFNOTES].ToString() != "")
			Tfiles.FNOTES = dr[RowFNOTES].ToString();

		if (dr[RowFHOLD56].ToString() != "")
			Tfiles.FHOLD56 = bool.Parse(dr[RowFHOLD56].ToString());

		if (dr[RowFNOBD].ToString() != "")
			Tfiles.FNOBD = bool.Parse(dr[RowFNOBD].ToString());

		if (dr[RowFNOTD].ToString() != "")
			Tfiles.FNOTD = bool.Parse(dr[RowFNOTD].ToString());

		if (dr[RowFLBLPRT].ToString() != "")
			Tfiles.FLBLPRT = bool.Parse(dr[RowFLBLPRT].ToString());

            this.Tfiless.Add(Tfiles);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
